*************************************************************************
***************Effect of remittances on human rights*********************
*************************************************************************
**************Using STATA for the analysis of the data*******************


********************************************************************************
*IMPORTANT NOTE* FIGURES 1 and 3 WERE DONE IN EXCEL
*Figure 1 was done using the data in the excel file "Remittances_HHRR.BPSR" on the sheet "Fig 1 Data"
*Figure 3 was done using the data in the excel file "Remittances_HHRR.BPSR" by filtering the data on Haiti only and choosing the variables 
*Remittances and CIRI, and using the line chart option
********************************************************************************


*Beginning the analysis of the data. Getting to know the data
***Declaring the data to be time-series
import excel "C:\Users\Any\Google Drive\Remitt - HuRights\Data\Remittances_HHRR.BPSR.xls", sheet("Database") firstrow
encode Country, gen (nation)
xtset nation Year, yearly 
set more off
set matsize 300
tab Year, gen(year)
tab nation, gen (nat)


***EFFECT OF REMITTANCES ON PHYSICAL INTEGRITY RIGHTS (PTS)
gen remprot = Remit_gdp*protest
gen remcivil = Remit_gdp*civil
gen lnpop = ln(population)
gen migra = ln(NetMigrat)
gen lngdp = ln(gdpgrowth)
gen remelect = Remit_gdp*elections 
recode ciri (0=8) (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1) (8=0), gen (Ciri)
recode Remit_gdp 0.0/5 = 1 5.01/10 = 2 10.01/15 = 3 15.01/20 = 4 20.01/28 = 5, gen (Remit)
recode Ciri 0/1 = 1 2/3 = 2 4/5 = 3 6/7 = 4 8=5, gen (ciri2)


gen lag_remit = Remit_gdp[_n-1]
gen lag_civil = civil[_n-1]
gen lag_remprot = remprot[_n-1]
gen lag_remcivil = remcivil[_n-1]
gen lag_mepv = mepv[_n-1]
gen lag_imf = imf[_n-1]
gen lag_migra = migra[_n-1]
gen lag_trade = trade[_n-1]
gen lag_gdpgrowth = gdpgrowth[_n-1]
gen lag_lngdp = lngdp[_n-1]
gen lag_pop = lnpop[_n-1]
gen lag_polity = polity[_n-1]
gen lag_sanctions = sanction2[_n-1]
gen lag_elections = elections[_n-1]
gen lag_protest = protest[_n-1]
gen lag_remelect = remelect[_n-1]
gen lag_ciri = ciri[_n-1]
gen lag_ciri2 = ciri[_n-2]
gen lag_Ciri = Ciri[_n-1]
gen lag_Ciri2 = Ciri[_n-2]

gen lag_civil2 = civil[_n-2]
gen lag_remit2 = Remit_gdp[_n-2]
gen lag_remprot2 = remprot[_n-2]
gen lag_remcivil2 = remcivil[_n-2]
gen lag_mepv2 = mepv[_n-2]
gen lag_imf2 = imf[_n-2]
gen lag_migra2 = migra[_n-2]
gen lag_trade2 = trade[_n-2]
gen lag_gdpgrowth2 = gdpgrowth[_n-2]
gen lag_lngdp2 = lngdp[_n-2]
gen lag_pop2 = lnpop[_n-2]
gen lag_polity2 = polity[_n-2]
gen lag_sanctions2 = sanction2[_n-2]
gen lag_elections2 = elections[_n-2]
gen lag_protest2 = protest[_n-2]
gen lag_remelect2 = remelect[_n-2]


***********************************
***Table 1. Descriptive statistics
***********************************
sum Ciri Remit_gdp elections civil mepv gdpgrowth lnpop polity imf trade NetMigrat sanction2 
codebook Ciri Remit_gdp elections civil mepv gdpgrowth lnpop polity imf trade NetMigrat sanction2 

sum Ciri Remit_gdp elections civil mepv gdpgrowth lnpop polity imf trade NetMigrat sanction2 if nation == 13





***********************************************************************************************************
********************EFFECT OF CIRI ON THE RIGHTS TO PHYSICAL INTEGRITY*************************************
***********************************************************************************************************

***Table 2, CIRI
ologit Ciri lag_Ciri Remit_gdp mepv imf NetMigrat gdpgrowth lnpop trade polity sanction2 elections civil nat1 nat2 nat3 nat4 nat5 nat6 nat7 nat8 nat9 nat10 nat11 nat12/*
*/ nat13 nat14 nat15 nat16 nat17 nat18 nat19 nat20 nat21
estimates store A, title(Remit*prot)

*** Table 2, CIRI -1
ologit Ciri lag_Ciri lag_remit lag_mepv lag_imf NetMigrat lag_gdpgrowth lag_pop lag_trade lag_polity lag_sanctions lag_elections lag_civil nat1 nat2 nat3 nat4 nat5 nat6 nat7 nat8 nat9 nat10 nat11 nat12/*
*/ nat13 nat14 nat15 nat16 nat17 nat18 nat19 nat20 nat21
estimates store B, title(Remit*elect1)

***Table 2, CIRI -2
ologit Ciri lag_Ciri2 lag_remit2 lag_mepv2 lag_imf2 NetMigrat lag_gdpgrowth2 lag_pop2 lag_trade2 lag_polity2 lag_sanctions2 lag_elections2 lag_civil2 nat1 nat2 nat3 nat4 nat5 nat6 nat7 nat8 nat9 nat10 nat11 nat12/*
*/ nat13 nat14 nat15 nat16 nat17 nat18 nat19 nat20 nat21
estimates store C, title(Remit*elect2)


esttab A B C, star(+ 0.10 * 0.05) se ar2
esttab A B C, se ar2


**********************************************************************
***ANNEX II*****************(ROBUSTNESS CHECK)************************
**********************************************************************
***Table 2, CIRI
xtpcse Ciri lag_Ciri Remit_gdp mepv imf NetMigrat gdpgrowth lnpop trade polity sanction2 elections civil nat1 nat2 nat3 nat4 nat5 nat6 nat7 nat8 nat9 nat10 nat11 nat12/*
*/ nat13 nat14 nat15 nat16 nat17 nat18 nat19 nat20 nat21
estimates store A, title(Remit*prot)

*** Table 2, CIRI -1
xtpcse Ciri lag_Ciri lag_remit lag_mepv lag_imf NetMigrat lag_gdpgrowth lag_pop lag_trade lag_polity lag_sanctions lag_elections lag_civil nat1 nat2 nat3 nat4 nat5 nat6 nat7 nat8 nat9 nat10 nat11 nat12/*
*/ nat13 nat14 nat15 nat16 nat17 nat18 nat19 nat20 nat21
estimates store B, title(Remit*elect1)

***Table 2, CIRI -2
xtpcse Ciri lag_Ciri2 lag_remit2 lag_mepv2 lag_imf2 NetMigrat lag_gdpgrowth2 lag_pop2 lag_trade2 lag_polity2 lag_sanctions2 lag_elections2 lag_civil2 nat1 nat2 nat3 nat4 nat5 nat6 nat7 nat8 nat9 nat10 nat11 nat12/*
*/ nat13 nat14 nat15 nat16 nat17 nat18 nat19 nat20 nat21
estimates store C, title(Remit*elect2)


esttab A B C, star(+ 0.10 * 0.05) se ar2
esttab A B C, se ar2


xtreg Ciri lag_Ciri Remit_gdp mepv imf NetMigrat gdpgrowth lnpop trade polity sanction2 elections civil nat1 nat2 nat3 nat4 nat5 nat6 nat7 nat8 nat9 nat10 nat11 nat12/*
*/ nat13 nat14 nat15 nat16 nat17 nat18 nat19 nat20 nat21
estimates store A, title(Remit*prot)

*** Table 2, CIRI -1
xtreg Ciri lag_Ciri lag_remit lag_mepv lag_imf NetMigrat lag_gdpgrowth lag_pop lag_trade lag_polity lag_sanctions lag_elections lag_civil nat1 nat2 nat3 nat4 nat5 nat6 nat7 nat8 nat9 nat10 nat11 nat12/*
*/ nat13 nat14 nat15 nat16 nat17 nat18 nat19 nat20 nat21
estimates store B, title(Remit*elect1)

***Table 2, CIRI -2
xtreg Ciri lag_Ciri2 lag_remit2 lag_mepv2 lag_imf2 NetMigrat lag_gdpgrowth2 lag_pop2 lag_trade2 lag_polity2 lag_sanctions2 lag_elections2 lag_civil2 nat1 nat2 nat3 nat4 nat5 nat6 nat7 nat8 nat9 nat10 nat11 nat12/*
*/ nat13 nat14 nat15 nat16 nat17 nat18 nat19 nat20 nat21
estimates store C, title(Remit*elect2)


esttab A B C, star(+ 0.10 * 0.05) se ar2
esttab A B C, se ar2


************************************************************************
**USING CLARIFY IN ORDER TO GET A CONDITIONAL PROBABILITY TABLE 
**TABLE 3 IS CONSTRUCTED WITH EACH OF THE FOLLOWING VALUES OBTAINED HERE
************************************************************************

*In order to perform the following tests, a program named "clarify" is used
*The program can be better understood through the following manual https://gking.harvard.edu/files/clarify.pdf, which includes installation instruction

*IMPORTANT NOTE: The results in the replication might be slightly different given that they are the result of a simulation


estsimp ologit Ciri lag_Ciri Remit_gdp mepv imf NetMigrat gdpgrowth lnpop trade polity sanction2 elections civil

setx Remit_gdp mean lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==8
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 4.78 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==8
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 9.56 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==8
simqi, prval (0 1 2 3 4 5 6 7 8)

setx Remit_gdp mean lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==7
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 4.78 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==7
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 9.56 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==7
simqi, prval (0 1 2 3 4 5 6 7 8)

setx Remit_gdp mean lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==6
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 4.78 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==6
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 9.56 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==6
simqi, prval (0 1 2 3 4 5 6 7 8)

setx Remit_gdp mean lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==5
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 4.78 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==5
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 9.56 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==5
simqi, prval (0 1 2 3 4 5 6 7 8)

setx Remit_gdp mean lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==4
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 4.78 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==4
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 9.56 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==4
simqi, prval (0 1 2 3 4 5 6 7 8)

setx Remit_gdp mean lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==3
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 4.78 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==3
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 9.56 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==3
simqi, prval (0 1 2 3 4 5 6 7 8)

setx Remit_gdp mean lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==2
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 4.78 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==2
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 9.56 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==2
simqi, prval (0 1 2 3 4 5 6 7 8)

setx Remit_gdp mean lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==1
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 4.78 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==1
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 9.56 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==1
simqi, prval (0 1 2 3 4 5 6 7 8)

setx Remit_gdp mean lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==0
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 4.78 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==0
simqi, prval (0 1 2 3 4 5 6 7 8)
setx Remit_gdp 9.56 lag_Ciri mean civil mean mepv mean gdpgrowth mean lnpop mean polity mean sanction2 mean elections mean if Ciri==0
simqi, prval (0 1 2 3 4 5 6 7 8)



************************************************************************
*************************QUANTILE REGRESSIONS***************************
**TABLE 4 IS CONSTRUCTED WITH EACH OF THE FOLLOWING VALUES OBTAINED HERE
************************************************************************
sqreg Ciri lag_Ciri Remit_gdp mepv imf NetMigrat gdpgrowth lnpop trade polity sanction2 elections civil, q(.1 ,3 .5 .70 .9)
estimates store A, title(Remit*protest)

**FOR TABLE 4
esttab A, se ar2
esttab A, star(+ 0.10 * 0.05) se ar2


*Testing whether the effect of remittances is the same at the 10th and 90th percentile
test[q10]Remit_gdp = [q90]Remit_gdp

*Obtaining a confidence interval for the difference in the effect of remittances at the 10th and 90th percentile
lincom [q10]Remit_gdp-[q90]Remit_gdp



************************************************************************
************GMM ESTIMATION, TWO STEP FOR TABLE 5************************
**TABLE 5 IS CONSTRUCTED WITH EACH OF THE FOLLOWING VALUES OBTAINED HERE
************************************************************************



*In order to perform the following tests, the program "ivreg2" needs to be installed
*For this, first type "ssc install ivreg2"



***TEST OF ENDOGENEITY (we estimated a basic gmm with one instrument)
ivregress gmm Ciri L.Ciri mepv imf gdpgrowth lnpop trade polity sanction2 elections civil (L.Remit_gdp = iv1), first
estat endogenous



***TIME T
ivregress gmm Ciri L.Ciri mepv imf gdpgrowth lnpop trade polity sanction2 elections civil (Remit_gdp = iv1 coast distance L2.Remit_gdp L.mepv L.imf L.gdpgrowth L.trade L.polity L.lnpop L.sanction2 L.elections L.civil), first
estimates store A, title(Remit*prot)
ivreg2 Ciri L.Ciri mepv imf gdpgrowth lnpop trade polity sanction2 elections civil (Remit_gdp = iv1 coast distance L2.Remit_gdp L.mepv L.imf L.gdpgrowth L.trade L.polity L.lnpop L.sanction2 L.elections L.civil), gmm2s
estimates store B, title(Remit*elect)
esttab A B, se ar2


***TIME T-1
ivregress gmm Ciri L.Ciri L.mepv L.imf L.gdpgrowth L.lnpop L.trade L.polity L.sanction2 L.elections L.civil (L.Remit_gdp = iv1 coast distance L2.Remit_gdp L.mepv L.imf L.gdpgrowth L.trade L.polity L.lnpop L.sanction2 L.elections L.civil), first
estimates store A, title(Remit*prot)
ivreg2 Ciri L.Ciri L.mepv L.imf L.gdpgrowth L.lnpop L.trade L.polity L.sanction2 L.elections L.civil (L.Remit_gdp = iv1 coast distance L2.Remit_gdp L.mepv L.imf L.gdpgrowth L.trade L.polity L.lnpop L.sanction2 L.elections L.civil), gmm2s
estimates store B, title(Remit*elect)
esttab A B, se ar2


***TIME T-2
ivregress gmm Ciri L2.Ciri L2.mepv L2.imf L2.gdpgrowth L2.lnpop L2.trade L2.polity L2.sanction2 L2.elections L2.civil (L.Remit_gdp = iv1 coast distance L2.Remit_gdp L.mepv L.imf L.gdpgrowth L.trade L.polity L.lnpop L.sanction2 L.elections L.civil), first
estimates store A, title(Remit*prot)
ivreg2 Ciri L2.Ciri L2.mepv L2.imf L2.gdpgrowth L2.lnpop L2.trade L2.polity L2.sanction2 L2.elections L2.civil (L.Remit_gdp = iv1 coast distance L2.Remit_gdp L.mepv L.imf L.gdpgrowth L.trade L.polity L.lnpop L.sanction2 L.elections L.civil), gmm2s
estimates store B, title(Remit*elect)
esttab A B, se ar2





************************************************************************************
***ANNEX I - Table 6. Multicollinearity assessment
*The values are right, but in Word, the location of the variables is not the same as
*the location presented here. Nevertheless, when confirming, the values coincide
************************************************************************************

corr Ciri Remit_gdp civil elections mepv gdpgrowth polity imf trade NetMigrat sanction2 lnpop
